import App from './App'

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif 
/** 
 * 每个页面都离不开几个组件
 * EchelonSolutions：窗口容器
 * SkylineNavigation:顶部导航栏
 * CentralHub:中间区域
 * RefinedTabBar:底部导航栏
 */
import EchelonSolutions from '@/components/EchelonSolutions'; // 窗口容器
import SkylineNavigation from '@/components/SkylineNavigation'; // 顶部导航栏
import CentralHub from '@/components/CentralHub' // 中间区域
import RefinedTabBar from '@/components/RefinedTabBar' // 底部导航栏 
import MyInput from '@/components/MyInput.vue' // 输入框
import MyTable from '@/components/MyTable.vue' // 表格
import MyPopup from '@/components/MyPopup.vue' // 弹出框
import MyForm from '@/components/MyForm.vue' // 表单
import MySelect from '@/components/MySelect.vue' // select
import MyDatePicker from '@/components/MyDatePicker.vue' // 时间 
import MyDropdown from '@/components/MyDropdown.vue' // 下拉  
import MyTreeTable from '@/components/MyTreeTable.vue' // 下拉  

Vue.component('EchelonSolutions', EchelonSolutions);
Vue.component('SkylineNavigation', SkylineNavigation);
Vue.component('CentralHub', CentralHub);
Vue.component('RefinedTabBar', RefinedTabBar);
Vue.component('MyInput', MyInput);
Vue.component('MyTable', MyTable);
Vue.component('MyPopup', MyPopup);
Vue.component('MyForm', MyForm);
Vue.component('MySelect', MySelect);
Vue.component('MyDatePicker', MyDatePicker);
Vue.component('MyDropdown', MyDropdown);
Vue.component('MyTreeTable', MyTreeTable);
console.log(`
每个页面都需要有这种格式谢谢
都在这个目录中components 
<echelon-solutions>
	<!-- 这里是顶部导航栏 -->
	<skyline-navigation> </skyline-navigation>
	<!-- 这里是中间区域 -->
	<central-hub> </central-hub>
	<!-- 这里是底部导航栏 -->
	<refined-tabBar> </refined-tabBar> 
</echelon-solutions>
js
{
    $eventBus: {
        emit(event: any, ...args: any[]): void;
        on(events: any, callback: any): void;
        subscribe(event: any, callback: any): void;
        clear(events: any): void;
        unsubscribe(event: any): void;
    };
	$storage: {
		set: (key: string, value: any, expireTime: number) => void;
		get: (key: string) => any;
		remove: (key: string) => void;
	};
	encrypt: (data: any, key?: any) => string;
	decrypt: (ciphertext: string, key?: any) => any; 
    $record: {
		recordAry: array; // 路由记录数组
		getCurrentRoute(): string; 获取当前路由
		upRecordAry(ary: any): void; // 更新路由记录数组
		navigateTo(data: any): void; // 导航到新页面
		switchTab(data: any): void; // 导航到tabBar 页面
		redirectTo(data: any): void; // 重定向路由
		reLaunch(data: any, ary?: any[]): void; // 关闭所有页面并跳转到应用程序的某个页面参数1是开始位置,参数2是添加记录可空
		navigateBack(delta?: number): void; // 返回到上一个页面或多个页面
		reopenPreviousPages(token: string, exemptedRoutes?: any[])
		/**
		 * 重新打开之前的页面
		 * @param {string} token 访问令牌
		 * @param {Array} exemptedRoutes 免除认证的页面路由列表
		 */
	};
}
`);

/* 全局配置 */
import Mixin from '@/components/mixin.js';
Vue.mixin(Mixin);
// 转换成字符串免得再手写
const vueProtoType = (vueInstance) => {
	const ob = Object.keys(vueInstance).map(key => `   ${key},`).join('\n');
	const str = Object.keys(vueInstance).map(key => `Vue.prototype.${key} = ${key};`).join('\n');
	return `{\n${ob}\n}\n${str}`;
}
/**
 *  全局方法 储存、路由跳转记录、加密、总线监听 
 *  自己写的插件 这样注册是为了调用时有提示
 */
import StorageCryptoRecordsEventBus from '@/ControlTower/records.js';
const {
	$record,
	$storage,
	encrypt,
	decrypt,
	$eventBus
} = StorageCryptoRecordsEventBus.install(Vue);
Vue.prototype.$record = $record;
Vue.prototype.$storage = $storage;
Vue.prototype.encrypt = encrypt;
Vue.prototype.decrypt = decrypt;
Vue.prototype.$eventBus = $eventBus;
/* appConfig-全局变量 */
import appConfig from './app.config.js' // 假设 app.config.js 中有多个配置项  
/**
 * 创建全局访问属性的方法
 * @param {Object} obj - 需要添加到 Vue.prototype 上的对象。
 * @param {Vue} vueInstance - Vue 实例 或 对象。
 * @param {string} parentKey - 父级对象的属性名，如果有的话。
 */
const createGlobalProperties = (obj, vueInstance, parentKey = '$') => {
	if (typeof obj !== 'object' || obj === null) {
		// 如果传入的参数不是一个有效的对象，则抛出错误
		console.error('Invalid input: The parameter should be a valid object');
		return;
	}

	// 遍历对象的所有键
	Object.keys(obj).forEach(key => {
		const fullKey = parentKey ? `${parentKey}${key.charAt(0).toLocaleUpperCase() + key.slice(1)}` : key;
		let value = obj[key];

		if (typeof value === 'object' && value !== null) {
			// 如果属性值是对象，则递归调用 createGlobalProperties 处理嵌套对象 
			// 递归调用 createGlobalProperties 来处理嵌套的对象属性
			createGlobalProperties(value, vueInstance, fullKey);
		} else {
			if (!(fullKey in vueInstance)) {
				vueInstance[fullKey] = fullKey;
			} else {
				// 如果属性已存在则发出警告
				console.warn(`Global property '${fullKey}' already exists. Skipping.`);
			}
		}
	});
	return vueInstance;
}

const app_config = createGlobalProperties(appConfig, {});
/* const {
	$PublicName,
	$PublicLogo,
	$PublicAgreement,
	$PublicPrivacy,
	$PublicService,
	$PublicBasePrefix,
	$PublicPaymentPrefix,
	$PublicUploads,
	$PublicEmpty,
	$MainMyuserChart,
	$MainMyuserBackground,
} = vueProtoType(app_config);
Vue.prototype.$PublicName = $PublicName;
Vue.prototype.$PublicLogo = $PublicLogo;
Vue.prototype.$PublicAgreement = $PublicAgreement;
Vue.prototype.$PublicPrivacy = $PublicPrivacy;
Vue.prototype.$PublicService = $PublicService;
Vue.prototype.$PublicBasePrefix = $PublicBasePrefix;
Vue.prototype.$PublicPaymentPrefix = $PublicPaymentPrefix;
Vue.prototype.$PublicUploads = $PublicUploads;
Vue.prototype.$PublicEmpty = $PublicEmpty;
Vue.prototype.$MainMyuserChart = $MainMyuserChart;
Vue.prototype.$MainMyuserBackground = $MainMyuserBackground; */
// 共享删除接口 
import {
	removePublic,
	updatePublic,
	createPublic,
	listPublic,
	postPublic
} from '@/services/base/bill/public.js'
Vue.prototype.$removePublic = removePublic;
Vue.prototype.$updatePublic = updatePublic;
Vue.prototype.$createPublic = createPublic;
Vue.prototype.$listPublic = listPublic;
Vue.prototype.$postPublic = postPublic;